package com.wey.Interceptor;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Component;
    import org.springframework.web.servlet.HandlerInterceptor;
    import org.springframework.web.servlet.ModelAndView;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    @Component
    public class RequestLoggingInterceptor implements HandlerInterceptor {

        private static final Logger logger = LoggerFactory.getLogger(RequestLoggingInterceptor.class);

        @Override
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            logger.info("Request URL: {}", request.getRequestURL());
            logger.info("HTTP Method: {}", request.getMethod());
            logger.info("Request Headers: {}", request.getHeaderNames());
            logger.info("Request Parameters: {}", request.getParameterMap());
            return true;
        }

        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            logger.info("Request processed successfully");
        }

        @Override
        public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
            if (ex != null) {
                logger.error("Request processing failed", ex);
            } else {
                logger.info("Request completed successfully");
            }
        }
    }
    